package com.yonyou.rabbitmq.provider.basic.routing;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.yonyou.rabbitmq.utils.RabbitmqUtils;

public class Provider {
    public static void main(String[] args) {
        Connection connection = null;
        Channel channel = null;

        try {
            //获取连接
            connection = RabbitmqUtils.getConnection();
            if (connection != null) {
                //获取通道
                channel = connection.createChannel();
                //通过通道声明交换机 交换机类型为direct
                channel.exchangeDeclare("logs_direct","direct");

                //发送消息
                String routingKey = "info";
                String message = "direct--routingKey，routingKey:"+routingKey;
                //交换机名称 路由键 消息其他属性 消息具体内容
                channel.basicPublish("logs_direct",routingKey,null,message.getBytes());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            System.out.println("生产者发布消息完成......");
            //释放资源
            RabbitmqUtils.close(channel,connection);
        }
    }
}
